package com.zhkj.txg.module.home.adapter

import android.graphics.Paint
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.lib.utils.AccountManager
import com.zhkj.lib.utils.SpanUtil
import com.zhkj.txg.R
import com.zhkj.txg.module.home.entity.SearchProductEntity
import com.zhkj.txg.module.product.ui.ProductDetailActivity
import com.zhkj.txg.utils.ImageUtils

class ShopAdapter : BaseQuickAdapter<SearchProductEntity, BaseViewHolder>(R.layout.item_home_goods), LoadMoreModule {

    init {
        setOnItemClickListener { _, _, position ->
            val goods = data[position]
            ProductDetailActivity.normalProduct(context, goods.id)
        }
    }

    override fun convert(helper: BaseViewHolder, item: SearchProductEntity) {
        val imageView = helper.setText(R.id.tvGoodsTitle, item.goodsName)
            .setText(R.id.tvGoodsPrice, SpanUtil.setMoneySymbol(item.price, true))
//            .setVisible(R.id.tvGoodsTag, item.isNew == "1")
            .getView<ImageView>(R.id.ivGoodsThumb)
        ImageUtils.loadImage(context, imageView, item.image)
        // 设置是显示市场价还是显示分享赚多少钱
//        with(helper.getView<TextView>(R.id.tvSellSpread)) {
//            if (AccountManager.isMember() && !item.shareEarn.isNullOrEmpty() && item.shareEarn != "0") {
//                setTextColor(ContextCompat.getColor(context, R.color.colorMain))
//                paint.flags = Paint.ANTI_ALIAS_FLAG
//                text = SpanUtil.setPrefixMoneyStr(price = item.shareEarn)
//            } else {
//                setTextColor(ContextCompat.getColor(context, R.color.colorLightText))
//                paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
//                paint.isAntiAlias = true
//                text = SpanUtil.setMoneySymbol(item.marketPrice)
//            }
//        }
    }
}